package jxau.xn.servlet;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class FileDownload extends HttpServlet{

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		    this.doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		    resp.setContentType("application/msword;charser=utf-8");
		    OutputStream os = resp.getOutputStream();
		    File file = new File("E:\\Workspaces\\MyEclipse 10\\.metadata\\.me_tcat\\webapps\\Servlet1.1\\upload\\bg.jpg");
		    FileInputStream fis = new FileInputStream(file);
		    byte[] b = new byte[500];
		    int i=-1;
		    while((i = fis.read(b)) != -1){
		    	os.write(b);
		    }
		    os.close();
		    fis.close();
	}
      
}
